// import { createRouter, createWebHashHistory } from 'vue-router'
// import login from '@/views/login/login.vue'
// import frame from '@/views/main/frame.vue'
// import myabsent from '@/views/absent/my.vue'
// import subabsent from '@/views/absent/sub.vue'
// import { useAuthStore } from "@/stores/auth"
// import publish from '@/views/inform/publish.vue'
// import inform_detail from '@/views/inform/detail.vue'
// import inform_list from '@/views/inform/list.vue'
// import staff_list from '@/views/staff/list.vue'
// import staff_add from '@/views/staff/add.vue'
// import home from '@/views/home/home.vue'



// const router = createRouter({
//   history: createWebHashHistory(import.meta.env.BASE_URL),
//   routes: [
//     {
//       path: '/',
//       name: 'frame',
//       component: frame,
//       children: [
//         { path: '/absent/my', name: 'myabsent', component: myabsent },
//         { path: '/absent/sub', name: 'subabsent', component: subabsent },
//         { path: '/inform/publish', name: 'inform_publish', component: publish },
//         { path: '/inform/list', name: 'inform_list', component: inform_list },
//         { path: '/inform/detail/:pk', name: 'inform_detail', component: inform_detail },
//         { path: '/staff/list/', name: 'staff_list', component: staff_list },
//         { path: '/staff/add', name: 'staff_add', component: staff_add },
//         { path: '/', name: 'home', component: home },
//       ]
//     },
//     {
//       path: '/login',
//       name: 'login',
//       // route level code-splitting
//       // this generates a separate chunk (About.[hash].js) for this route
//       // which is lazy-loaded when the route is visited.
//       // 不要用这种方式加载
//       // component: () => import('../views/login/login.vue')
//       component: login
//     }
//   ]
// })

import { createRouter, createWebHashHistory } from 'vue-router'
import {useAuthStore} from "@/stores/auth"
import frame_routes from "@/router/frame"
import login_routes from "@/router/login"

const router = createRouter({
  history: createWebHashHistory(import.meta.env.BASE_URL),
  routes: frame_routes.concat(login_routes)
})



// 全局导航守卫
router.beforeEach((to, from) => {
  // 判断用户是否登录，如果没有登录，并且访问非登录页面，跳转到登录页面
  const authStore = useAuthStore()
  if (!authStore.is_logined && to.name != 'login') {
    return { name: 'login' }
  }
})

export default router
